home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / lang / c++-part2 / 17804 < prev    next >
Encoding:
Internet Message Format  |  1996-08-05  |  1.9 KB

  1. Path: nntp-trd.UNINETT.no!usenet
  2. From: Paul Kenneth Egell-johnsen <paulken4@afrodite.kih.no>
  3. Newsgroups: comp.lang.c++
  4. Subject: Re: How do I put DIFFERENT classes in the same linked list?
  5. Date: Wed, 17 Apr 1996 19:12:36 +0200
  6. Organization: UNINETT news service    
  7. Message-ID: <31752684.13CC@afrodite.kih.no>
  8. References: <4ka938$bj6@wintermute.ecs.fullerton.edu> <marnoldDpJ9HK.41D@netcom.com> <3173563E.16DF@esec.ch>
  9. NNTP-Posting-Host: afrodite.kih.no
  10. Mime-Version: 1.0
  11. Content-Type: text/plain; charset=us-ascii
  12. Content-Transfer-Encoding: 7bit
  13. X-Mailer: Mozilla 2.01 (X11; I; HP-UX A.09.05 9000/720)
  14.  
  15. Oliver Plohmann wrote:
  16. > > >I'm trying to write a program where I need to maintain a linked list of
  17. > > >various items. Each item is a class, but each item is different from another
  18. > > >item. Let me give an example to clarify:
  19. > Hello,
  20. > I haven't followed the thread whether using virtual functions will do want you were looking
  21. > for. But inserting instances of different classes into a parameterized linked list node is not
  22. > possible.
  23.  
  24. My simple solution is, make all of your classes derived from
  25. another class (called universe in this example). Then make the
  26. linked list point to univers. Thereafter you can insert all the
  27. other classes (as they are derived from univers) into the linked
  28. list. Make the linked list derived from univers, then you have
  29. the possibility to have linked lists within the linked list,
  30. great for 'group' functions in an graphics editor, to use one
  31. example.
  32.  
  33. If you make the linked list class a template class, then you can
  34. use all kinds of objects (even if they aren't derived of
  35. univers) in a linked list (but it has to be heterogenous ie.
  36. only objects of that type, or derived from it since we are
  37. speaking of C++).
  38.  
  39. The specifics I think you have yourself.
  40.  
  41. Paul K Egell-Johnsen,
  42.  
  43. mailto:paulken4@afrodite.kih.no
  44. http://afrodite.kih.no:8001/studenter/paulken4/frames/
  45.